package com.ctshk.app.order.airexpress.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.AppReq;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.airexpress.dto.app.AirportExpressOrderCacheDTO;
import com.ctshk.rpc.order.airexpress.req.AirportExpressOrderListReq;
import com.ctshk.rpc.order.airexpress.req.app.AirportExpressOrderAppReq;
import com.ctshk.rpc.order.airexpress.service.IAirportExpressOrderAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

/**
 * <p>
 * 机场快线 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-23
 */
@Slf4j
@RestController
@RequestMapping("/air/express/h5")
@Api(value = "机场快线订单服务-H5", tags = "机场快线订单服务-H5")
public class AirExpressOrderH5Controller extends BaseController {

    @DubboReference
    IAirportExpressOrderAppService airportExpressOrderAppService;

    @ApiOperation(value = "机场快线-订单中心-提交订单", notes = "机场快线-订单中心-提交订单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "机场快线-订单中心-提交订单", operDesc = "机场快线-订单中心-提交订单")
    @PostMapping("/submit")
    public Result submit(@Valid @RequestBody AirportExpressOrderAppReq airportExpressOrderAppReq, @ApiIgnore AppReq appReq) {
        airportExpressOrderAppReq.setUserId(getCurrentUserAllowNotLogInUserId());
        return airportExpressOrderAppService.submit(airportExpressOrderAppReq, getCurrentUserAllowNotLogInUserId(), appReq);
    }

    @ApiOperation(value = "机场快线-订单中心-查询订单列表", notes = "机场快线-订单中心-查询订单列表")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "机场快线-订单中心-查询订单列表", operDesc = "机场快线-订单中心-查询订单列表")
    @PostMapping("/list")
    public Result<AirportExpressOrderCacheDTO> list(@RequestBody AirportExpressOrderListReq airportExpressOrderListReq) {
        airportExpressOrderListReq.setUserId(getCurrentUser(getRequest()).getId());
        AirportExpressOrderCacheDTO list = airportExpressOrderAppService.list(airportExpressOrderListReq);
        return Result.success(list);
    }
}
